<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use app\Models\ArticleToTag;

class Article extends Model
{
    use HasFactory;

    protected $table = 'articles';

    // 关联标签表
    public function tags()
    {
        return $this->belongsToMany(Tag::class, 'article_to_tag', 'article_id', 'tag_id');
        //return $this->belongsToMany(Tag::class, ArticleToTag::class);
    }

    public function category()
    {
        return $this->belongsTo(Category::class, 'category_id');
    }
}
